package com.ruoyi.common.config.mybatis.method;

import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @Classname LogicDelete
 * @Author: sunluquan
 * @Date: 2021/12/23 11:26
 * @Description TODO
 * 逻辑删除 根据 entity 删除
 */
public class LogicDelete extends AbstractLogicDeleteMethod {

    /**
     * 逻辑删除sql方法  如果当前表中没有逻辑删除标识  则不支持此方法的调用
     * @param mapperClass
     * @param modelClass
     * @param tableInfo
     * @return
     */
    @Override
    public MappedStatement reachableInjectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        String sql;
        SqlMethod sqlMethod = SqlMethod.LOGIC_DELETE;
        sql = String.format(sqlMethod.getSql(), tableInfo.getTableName(), sqlLogicSet(tableInfo),
                sqlWhereEntityWrapper(true, tableInfo),
                sqlComment());
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return addUpdateMappedStatement(mapperClass, modelClass, sqlMethod.getMethod(), sqlSource);

    }
}
